/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kurs;

/**
 *
 * @author Matrix
 */
public class DynStackOfQueue extends DynStack {

    public String printFullState() throws EmptyException {
        if (isEmpty()) throw new EmptyException("Stack is empty, try to push some elements");
        HardNode temp = (HardNode)top;
        String output = new String();
        while (temp != null) {
            //System.out.println(temp.info);
            output += temp.getInfo();
            output += ":\n";
            try {
                output += "  "+ temp.queue.printState() + "\n";
            }
            catch (EmptyException eE) {
                //System.out.println(eE.getMessage());
                output += "  "+ eE.getMessage() + "\n";
            }
            temp = (HardNode)temp.link;
        }
        return output;

    }

    public BaseNode fullFind(String info) throws EmptyException, NotFoundException{
        if (isEmpty()) throw new EmptyException("Stack is empty, try to push some elements");
        try {
            HardNode temp = (HardNode)find(info);
            return temp;
        }
        catch (NotFoundException nFE) {
            HardNode temp = (HardNode)top;
            do {
                try {
                    BaseNode tempQ = temp.queue.find(info);
                    return tempQ;
                }
                catch (EmptyException eE) {
                    //System.out.println(eE.getMessage());
                    temp = (HardNode)temp.link;
                }
                catch (NotFoundException QueueNFE) {
                    //System.out.println(QueueNFE.getMessage());
                    temp = (HardNode)temp.link;
                }
                //temp = (HardNode)temp.link;
            }   while (temp != null);
            if (temp == null) throw new NotFoundException("Not founded");
            else return temp;
        }
    } 
}
